package ${package.ServiceImpl};

import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.yizheng.stock.common.core.util.BeanUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import ${cfg.voPackageName}.${cfg.voName};
import ${cfg.dtoPackageName}.${cfg.dtoName};

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
@Transactional(readOnly = false,rollbackFor = Exception.class)
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {



    @Autowired
    private ${table.mapperName} ${cfg.mapperName};




    /**
     * 分页查询
     * @param page 分页信息
     * @param dto 查询条件
     * @return 返回IPage<${cfg.voName}>
     */
    @Override
    public IPage<${cfg.voName}> findListByPage(Page page, ${cfg.dtoName} dto) {
        QueryWrapper<${entity}> query = new QueryWrapper<>();
        query.setEntity(BeanUtils.clone(dto,${entity}.class));
        IPage<${entity}> data = this.page(page,query);
        IPage<${cfg.voName}> voPage = BeanUtils.copyPageList(data, new Page<>(), ${cfg.voName}.class);
        return voPage;
    }

    /**
     * 查询列表数据
     * @param dto 查询条件信息
     * @return 列表数据
     */
    @Override
    public List<${cfg.voName}> findList(${cfg.dtoName} dto) {
        QueryWrapper<${entity}> query = new QueryWrapper<>();
        query.setEntity(BeanUtils.clone(dto, ${entity}.class));
        return BeanUtils.copyList(this.list(query),${cfg.voName}.class);
    }



    /**
     * 新增数据
     * @param dto 数据信息
     * @return 返回操作是否成功
     */
    @Override
    public boolean add(${cfg.dtoName} dto) {
        return this.save(BeanUtils.clone(dto,${entity}.class));
    }

    /**
     * 根据id查询
     * @param id 主键id
     * @return  ${cfg.voName}
     */
    @Override
    public  ${cfg.voName} findById(int id) {
        ${entity} entity = this.getById(id);
        ${cfg.voName} vo = BeanUtils.clone(entity,${cfg.voName}.class);
        return vo;
    }


    /**
     * 更新数据
     * @param dto 数据信息
     * @return 返回操作是否成功
     */
    @Override
    public boolean edit(${cfg.dtoName} dto) {
        return this.updateById(BeanUtils.clone(dto,${entity}.class));
    }

    /**
     * 根据id删除
     * @param id 主键id
     * @return 返回操作是否成功
     */
    @Override
    public boolean deleteById(int id) {
        return this.removeById(id);
    }
}
</#if>
